<template>
  <div class="mod-config">
    <basic-container>
      <navigation
        :sign="{ a: true, b: false, c: false, d: false, e: false }"
      ></navigation>
      <div class="boxsty zhiBiao">
        <div class="flex justifyContentSpaceBetween">
          <div class="tabletext">考核事件填报</div>
        </div>
        <el-form
          :inline="true"
          :model="dataForm"
          @keyup.enter.native="getDataList()"
          class="form-inline"
        >
          <el-form-item label="考核名称">
            <el-input
              v-model="dataForm.userName"
              placeholder="考核名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="考核状态">
            <el-input
              v-model="dataForm.userCode"
              placeholder="考核状态"
            ></el-input>
          </el-form-item>
          <el-form-item label="考核对象">
            <el-input
              v-model="dataForm.userCode"
              placeholder="考核对象"
            ></el-input>
          </el-form-item>
          <el-form-item label="考核时间">
            <el-input
              v-model="dataForm.userCode"
              placeholder="考核对象"
            ></el-input>
          </el-form-item>
          <el-form-item label="是否特殊加扣">
            <el-input
              v-model="dataForm.userCode"
              placeholder="考核对象"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              class="marginLeft"
              @click="getDataList()"
              >检索</el-button
            >
          </el-form-item>
        </el-form>
        <div class="flex justify-between align-center margin-tb-20">
          <el-radio-group>
            <el-radio label="PERSON">个人</el-radio>
            <el-radio label="GROUP">组</el-radio>
            <el-radio label="DEPT">机构</el-radio>
          </el-radio-group>
          <div>
            <el-button type="primary">批量填报</el-button>
            <el-button type="primary">特殊加扣</el-button>
          </div>
        </div>
        <el-table
          :data="dataList"
          v-loading="dataListLoading"
          stripe
          class="avue-crud"
          height="450px"
        >
          <el-table-column
            prop=""
            label="序号"
            :formatter="nShowIndex"
          ></el-table-column>
          <el-table-column prop="userCode" label="考核对象"></el-table-column>
          <el-table-column prop="userName" label="员工编号"></el-table-column>
          <el-table-column prop="lx" label="所属考核"></el-table-column>
          <el-table-column prop="jjxName" label="指标类别"></el-table-column>
          <el-table-column prop="jjJe" label="指标项"></el-table-column>
          <el-table-column prop="jjDate" label="单位"></el-table-column>
          <el-table-column prop="jjFfzt" label="权重"></el-table-column>
          <el-table-column prop="jjSm" label="目标值"> </el-table-column>
          <el-table-column prop="jjSm" label="完成值"> </el-table-column>
          <el-table-column prop="jjSm" label="得分"> </el-table-column>
          <el-table-column prop="jjSm" label="最终得分"> </el-table-column>
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                @click="addOrUpdateHandle(scope.row.id)"
                >原因查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          >
          </el-pagination>
        </div>
      </div>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, delObj } from "@/api/jiangjin/jiangjingrjcjlb";
import { mapGetters } from "vuex";
import { getJiangJinBm } from "@/api/admin/dept";

export default {
  data() {
    return {
      dataForm: {
        userName: "",
        userCode: "",
        jjFfzt: "",
        jjDeptId: "",
      },
      options: [
        { value: "未发放", label: "未发放" },
        { value: "已发放", label: "已发放" },
      ],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      addOrUpdateAllVisible: false,
      deptId: "", //负责部门ID
      deptName: "", //负责部门名称
    };
  },
  components: {},
  created() {},
  mounted() {
    this.getJiangJinJg();
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    //获取奖金管理人机构
    getJiangJinJg() {
      getJiangJinBm().then((res) => {
        if (res.data.data != null && res.data.data.length > 0) {
          this.deptId = "";
          this.deptName = "";
          this.deptId = res.data.data[0].deptId;
          this.deptName = res.data.data[0].name;
          this.getDataList();
        } else {
          this.$notify.closeAll();
          this.$notify.error("没有相关负责部门");
          this.deptName = "无相关负责部门";
        }
      });
    },
    //列显示重新定义
    nFormatterShow(row, column, cellValue, index) {
      if (cellValue) {
        return cellValue.toFixed(2);
      } else {
        return cellValue;
      }
    },
    nShowIndex(row, column, cellValue, index) {
      return index + 1;
    },
    fTTable(row, column, cellValue, index) {
      if (cellValue) {
        return this.$moment(cellValue).format("YYYY-MM-DD");
      } else {
        return cellValue;
      }
    },

    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$set(this.dataForm, "jjDeptId", this.deptId);
      fetchList(
        Object.assign(
          {
            current: this.pageIndex,
            size: this.pageSize,
          },
          this.dataForm
        )
      ).then((response) => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total;
      });
      this.dataListLoading = false;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, this.deptId);
      });
    },
    addOrUpdateAll() {
      this.addOrUpdateAllVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdateAll.init(this.deptId);
      });
    },
    // 删除
    deleteHandle(id) {
      this.$confirm("是否确认删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(id);
        })
        .then((data) => {
          this.$notify.closeAll();
          this.$notify.success("删除成功");
          this.getDataList();
        });
    },
  },
};
</script>
